using System.Collections.Generic;
using Core;
using UnityEngine;

namespace LST_Test
{
    public class GiveEnumerator
    {
        private static readonly int[] Dirs = new[]
        {
            1, 3, 5, 7, 9
        };

        public IEnumerable<int> Neighbors()
        {
            for (int i = 0; i < Dirs.Length; i++)
            {
                yield return Dirs[i];
            }
        }
    }

    public class TestEnumerator : MonoBehaviour
    {
        void Start()
        {
            GiveEnumerator test = new GiveEnumerator();
            TestMoveNext(test);
            TestForeach(test);
        }

        private void TestMoveNext(GiveEnumerator test)
        {
            var iter = test.Neighbors().GetEnumerator();
            int i = 0;
            while (iter.MoveNext())
            {
                log.d($"Test Enumerator, {i} - {iter.Current}");
                ++i;
            }
        }

        private void TestForeach(GiveEnumerator test)
        {
            int i = 0;
            foreach (var v in test.Neighbors())
            {
                log.d($"Test ForEach, {i} - {v}");
                ++i;
            }
        }
    }
}
